package dem1;

import java.util.*;
import java.util.function.Consumer;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-03-25
 * Time: 21:40
 */
public class Test1 {
    public static void main(String[] args) {
        Integer[] arr = {2,4,6,1,3,2,9,7,5,8};
        Arrays.sort(arr,(o1,o2) -> {return o2 - o1;});
        Arrays.sort(arr,(o1,o2) -> o2 - o1);
        System.out.println(Arrays.toString(arr));
        System.out.println("==========================");

        String[] str = {"aaa","a","aa","aaaa"};
        Arrays.sort(str, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });
        System.out.println(Arrays.toString(str));
        System.out.println("==========================");
        Arrays.sort(str, (o1,o2) ->o2.length() - o1.length());
        System.out.println(Arrays.toString(str));

        System.out.println("==========================");
        GirlFriend[] girlFriends = new GirlFriend[]{new GirlFriend("林黛玉",15,150),
        new GirlFriend("薛宝钗",15,155),new GirlFriend("刘姥姥",70,160)};

        Arrays.sort(girlFriends, (o1, o2) -> {
                int result = o1.getAge() == o2.getAge() ? 0 : o1.getAge() - o2.getAge();
                result = result == 0 ? o1.getTall() - o2.getTall() : result;
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
        });

        System.out.println(Arrays.toString(girlFriends));
        System.out.println("=======================");
        int ret = sum(10);
        System.out.println(ret);

        System.out.println("==================");
        Collection<Integer> collection = new ArrayList<>();
        collection.add(12);
        collection.add(15);

        for (Integer integer : collection) {
            System.out.println(integer);
        }

        System.out.println("===================");

        Iterator<Integer> iterator = collection.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }

//        collection.forEach(integer -> {
//                System.out.println(integer);
//        });

        //System.out.println(collection);
    }

    public static int sum(int num){
        int amount = 1;
        for (int i = 1; i <= num; i++) {
            amount = (amount +1) * 2;
        }
        return amount;
    }
}
